home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d18
/
rodent_3.arc
/
QCRODENT.C
< prev
next >
Wrap
Text File
|
1991-04-28
|
7KB
|
192 lines
/*********************************************************/
/* qcrodent.c */
/* */
/* Demo program to show how to define a mouse graphics */
/* cursor. */
/* */
/* Written in Microsoft QuickC version 2.01. */
/* */
/* Hardware req'ts : CGA, EGA, or VGA */
/* Microsoft-compatible mouse */
/* */
/*********************************************************/
#include <dos.h>
#include <stdio.h>
#include <graph.h>
/* Define an hourglass-shaped mouse graphics cursor */
unsigned mcursor[2][16] =
{
/* Screen mask; this is ANDed with screen */
{
0x0001, /* 0000000000000001 */
0x0001, /* 0000000000000001 */
0x8003, /* 1000000000000011 */
0xc7c7, /* 1100011111000111 */
0xe38f, /* 1110001110001111 */
0xf11f, /* 1111000100011111 */
0xf83f, /* 1111100000111111 */
0xfc7f, /* 1111110001111111 */
0xf83f, /* 1111100000111111 */
0xf11f, /* 1111000100011111 */
0xe38f, /* 1110001110001111 */
0xc7c7, /* 1100011111000111 */
0x8003, /* 1000000000000011 */
0x0001, /* 0000000000000001 */
0x0001, /* 0000000000000001 */
0x0000, /* 0000000000000000 */
},
/* Cursor mask; this is XORed with screen */
{
0x0000, /* 0000000000000000 */
0x7ffc, /* 0111111111111100 */
0x2008, /* 0010000000001000 */
0x1010, /* 0001000000010000 */
0x0820, /* 0000100000100000 */
0x0440, /* 0000010001000000 */
0x0280, /* 0000001010000000 */
0x0100, /* 0000000100000000 */
0x0280, /* 0000001010000000 */
0x0440, /* 0000010001000000 */
0x0820, /* 0000100000100000 */
0x1010, /* 0001000000010000 */
0x2008, /* 0010000000001000 */
0x7ffc, /* 0111111111111100 */
0x0000, /* 0000000000000000 */
0x0000 /* 0000000000000000 */
}
};
union REGS regs; /* 80x86 processor registers */
struct SREGS sregs; /* segment registers */
/* function prototypes */
void msgetstatus(int *, int *, int *); /* get cursor loc & buttons */
void mshidecur(void); /* hide mouse cursor */
int msinit(void); /* initialize mouse driver, return # of buttons */
void mssetcur(void); /* set mouse cursor shape */
void msshowcur(void); /* show (unhide) mouse cursor */
void showbutton(int, int);
main()
{
int buttons; /* # of mouse buttons */
int mouse_x, mouse_y, mouse_button; /* Mouse loc & button info */
int rightbutton;
/* Set video to CGA 640x200 BW mode */
if (!_setvideomode(_HRESBW))
{
puts("This program requires a CGA or other color adapter!");
exit(1);
}
/* msinit() return button count; 0 = no mouse */
if (!(buttons = msinit()))
{
puts("No mouse detected.");
exit(1);
}
if (buttons == 3) /* determine where right button will be shown */
rightbutton = 42;
else
rightbutton = 35;
puts("╔════╗ ┌───┐ ┌───┐");
puts("║QUIT║ x = xxx y = yyy │ │ │ │");
puts("╚════╝ └───┘ └───┘");
if (buttons == 3)
{
_settextposition(1, rightbutton - 1);
_outtext("┌───┐");
_settextposition(2, rightbutton - 1);
_outtext("│ │");
_settextposition(3, rightbutton - 1);
_outtext("└───┘");
}
mssetcur(); /* Set mouse cursor to mcursor */
msshowcur(); /* Show mouse cursor */
do /* main program loop */
{
msgetstatus(&mouse_x, &mouse_y, &mouse_button);
_settextposition(2, 13);
printf("%3d", mouse_x);
_settextposition(2, 22);
printf("%3d", mouse_y);
showbutton(28, mouse_button & 1);
showbutton(rightbutton, mouse_button & 2);
if (buttons == 3)
showbutton(35, mouse_button & 4);
} while (mouse_button != 1 || mouse_x > 48 || mouse_y > 24);
mshidecur();
_setvideomode(_DEFAULTMODE); /* reset screen */
} /* end main */
/**********************************************************************/
/* get cursor location and button status */
void msgetstatus(int *ms_x, int *ms_y, int *ms_b)
{
regs.x.ax = 3; /* function 3 = get status */
int86(0x33, ®s, ®s);
*ms_x = regs.x.cx; /* horizontal cursor location */
*ms_y = regs.x.dx; /* vertical cursor location */
*ms_b = regs.x.bx; /* button info: 1 = left, 2 = right, 4 = center */
/* note that the button bits are independent of each other; */
/* ie., if the left and right buttons are both pressed the */
/* returned button value is 3. */
} /* end msgetstatus */
/**********************************************************************/
/* hide mouse cursor */
void mshidecur(void)
{
regs.x.ax = 2; /* function 2 */
int86(0x33, ®s, ®s);
} /* end mshidecur */
/**********************************************************************/
/* initialize mouse driver & return number of buttons */
/* Uses int 33h function 0. If mouse detected, the interrupt returns */
/* a non-zero value in AX */
int msinit(void)
{
regs.x.ax = 0; /* function 0 is init driver */
if (int86(0x33, ®s, ®s))
return(regs.x.bx);
else
return(0);
} /* end msinit */
/**********************************************************************/
/* set up new cursor image via function 9. Bit mask for new cursor */
/* is in ES:DX, cursor hot spot is in BX and CX */
void mssetcur(void)
{
segread(&sregs); /* get segment registers */
sregs.ds = sregs.es; /* set ES to data segment */
regs.x.ax = 9; /* function 9 */
regs.x.bx = 7; /* set horiz. hot spot to midpoint of hourglass */
regs.x.cx = 7; /* likewise for vertical hot spot */
regs.x.dx = (unsigned)mcursor; /* ptr to mask */
int86x(0x33, ®s, ®s, &sregs); /* do it */
} /* end mssetcur */
/**********************************************************************/
/* show mouse cursor. function 0 (initialize) leaves the cursor */
/* hidden so we have to explicitly turn it on. */
void msshowcur(void)
{
regs.x.ax = 1; /* function 1 */
int86(0x33, ®s, ®s);
} /* end msshowcur */
/**********************************************************************/
/* Light or blank a block to show button press */
void showbutton(int loc, int condition)
{
_settextposition(2, loc);
if(condition) /* if the button is pressed */
_outtext("███"); /* light it up */
else
_outtext(" "); /* else turn it off */
}